package com.ids.actions;

import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.ids.bean.UserCreationBean;
import com.ids.service.UserCreationService;
import com.ids.util.Constants;
import com.opensymphony.xwork2.ActionSupport;

public class UserCreation extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private UserCreationBean user;

	public String execute() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		UserCreationService usercreationService = new UserCreationService();
		Set<String> resultUserCreation = usercreationService.createUserAccount(user);
		String email = user.getPrimaryEmail();
		String empCode = user.getEmpCode();
		String pwd = user.getPassword();
		if (resultUserCreation.contains(Constants.FAILURE)) {
			request.setAttribute(Constants.USER_CREATION_MESSAGE,"User Creation failed");
		} else if (resultUserCreation.contains(Constants.SUCCESS)) {
			request.setAttribute(Constants.USER_CREATION_MESSAGE,"User Created successfully");
			usercreationService.sendMail(email, empCode, pwd);

		}
		return SUCCESS;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	public UserCreationBean getUser() {
		return user;
	}

	public void setUser(UserCreationBean user) {
		this.user = user;
	}

}
